<template>
  <div>
    <input
      type="text"
      placeholder="请输入要搜索的关键字"
      v-if="!flag"
      ref="tex"
    />
    <button v-else @click="qhBtn">切换</button>
  </div>
</template>

<script>
// dom.focus() 获取焦点
export default {
  name: 'App',
  components: {},
  props: {},
  data() {
    return {
      flag: true,
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    qhBtn() {
      this.flag = !this.flag
      this.$nextTick(() => {
        this.$refs.tex.focus()
      })
    },
  },
}
</script>

<style scoped></style>
